package com.ruoyi.project.system.wxAccesstoken.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.wxAccesstoken.domain.WxAccesstoken;
import com.ruoyi.project.system.wxAccesstoken.service.IWxAccesstokenService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 微信AccessToken信息操作处理
 * 
 * @author zhangshilin
 * @date 2019-08-07
 */
@Controller
@RequestMapping("/system/wxAccesstoken")
public class WxAccesstokenController extends BaseController
{
    private String prefix = "system/wxAccesstoken";
	
	@Autowired
	private IWxAccesstokenService wxAccesstokenService;
	
	@RequiresPermissions("system:wxAccesstoken:view")
	@GetMapping()
	public String wxAccesstoken()
	{
	    return prefix + "/wxAccesstoken";
	}
	
	/**
	 * 查询微信AccessToken列表
	 */
	@RequiresPermissions("system:wxAccesstoken:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WxAccesstoken wxAccesstoken)
	{
		startPage();
        List<WxAccesstoken> list = wxAccesstokenService.selectWxAccesstokenList(wxAccesstoken);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出微信AccessToken列表
	 */
	@RequiresPermissions("system:wxAccesstoken:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxAccesstoken wxAccesstoken)
    {
    	List<WxAccesstoken> list = wxAccesstokenService.selectWxAccesstokenList(wxAccesstoken);
        ExcelUtil<WxAccesstoken> util = new ExcelUtil<WxAccesstoken>(WxAccesstoken.class);
        return util.exportExcel(list, "wxAccesstoken");
    }
	
	/**
	 * 新增微信AccessToken
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存微信AccessToken
	 */
	@RequiresPermissions("system:wxAccesstoken:add")
	@Log(title = "微信AccessToken", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WxAccesstoken wxAccesstoken)
	{		
		return toAjax(wxAccesstokenService.insertWxAccesstoken(wxAccesstoken));
	}

	/**
	 * 修改微信AccessToken
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		WxAccesstoken wxAccesstoken = wxAccesstokenService.selectWxAccesstokenById(id);
		mmap.put("wxAccesstoken", wxAccesstoken);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存微信AccessToken
	 */
	@RequiresPermissions("system:wxAccesstoken:edit")
	@Log(title = "微信AccessToken", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WxAccesstoken wxAccesstoken)
	{		
		return toAjax(wxAccesstokenService.updateWxAccesstoken(wxAccesstoken));
	}
	
	/**
	 * 删除微信AccessToken
	 */
	@RequiresPermissions("system:wxAccesstoken:remove")
	@Log(title = "微信AccessToken", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(wxAccesstokenService.deleteWxAccesstokenByIds(ids));
	}
	
}
